#!/usr/bin/python3
# -*- coding: utf8 -*-
# Date   : 2021/09/01
# Author : Kwan
# Email  : allenxian@live.com
# Blog   : https://my.oschina.net/u/4173440

from agent import Collector


if __name__ == "__main__":
    import sys, getopt

    def get_argvs(argv):
        server = "http://localhost:5000"
        intervals = 5
        try:
            opts, args = getopt.getopt(argv,"hs:i:",["server=","interval="])
            for opt, arg in opts:
                arg = arg.replace(" ","")
                if opt in ("-s", "--server"):
                    server = arg
                elif opt in ("-i", "--interval"):
                    intervals = int(arg)
                    if intervals < 5:
                        intervals = 5
        except Exception as e:
            print(f"启动参数错误：{e}")
        return server, intervals

    server_url, interval_time = get_argvs(sys.argv[1:])
    print(f"服务地址：{server_url}, 间隔时间：{interval_time} 秒")
    ClientCollector = Collector(url=server_url)
    try:
        ClientCollector.service_start(interval_time)
    except KeyboardInterrupt:
        pass